package com.hns.can.mainte.web;

import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.service.CommonInitParamService;
import com.hns.can.common.vo.CommonParamsVo;
import com.hns.can.common.web.BaseController;
import com.hns.can.mainte.service.ChargingCountService;
import com.hns.can.mainte.vo.ChargingCountVo;
import com.hns.tool.export.ExportUtil;
import com.hns.tool.pub.DateTool;

/**
 * 电池充放电统计Controller
 * @author:zhangzq
 * @email:
 * @version Revision 2.0.0
 */
@Controller
@RequestMapping("/chargingCount")
public class ChargingCountController extends BaseController {
	
	final private String[] headerNames = new String[]{"车牌号","运营线路","所属机构","车辆型号","电池材料类型","充电次数","过冲次数","过放次数"};
	final private String[] headerFields = new String[]{"licPltNo","lineName","organName","carType","bteryMaterialType","chargeCount","chargeInCount","chargeOutCount"};

    
    @Autowired
    private ChargingCountService chargingCountService;
    @Autowired
    private CommonInitParamService commonInitParamService;
    
    /**
     * 查询电池充放电统计数据
     * @param params
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/searchChargingCount")
	@ResponseBody
    public Object searchChargingCount(CommonParamsVo params) throws Exception {
    	SysUserEntity user = this.getCurrentUser().getUser();
    	commonInitParamService.initParamsLimitCar(params, user, Arrays.asList("T_COMM_CAR_CHARGE_INFO","T_COMM_MFT_ALM"));
		List<ChargingCountVo> list = chargingCountService.getChargingCountData(params);
		return this.getReturnResult(list);
    }
    
    /**
     * 导出电池充放电统计数据Excel文件
     * @param params
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/exportChargingCountExcel")
    public void exportChargingCountExcel(CommonParamsVo params,HttpServletResponse response) throws Exception {
        List<ChargingCountVo> list = getChargingCountData(params);
        ExportUtil.exportFiles(Arrays.asList(headerNames), Arrays.asList(headerFields), list, response, "excel", "ChargingCount"+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "电池充放电统计数据");
    }
    
    /**
     * 导出电池充放电统计数据Pdf文件
     * @param params
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/exportChargingCountPdf")
    public void exportChargingCountPdf(CommonParamsVo params,HttpServletResponse response) throws Exception {
        List<ChargingCountVo> list = getChargingCountData(params);
        ExportUtil.exportFiles(Arrays.asList(headerNames), Arrays.asList(headerFields), list, response, "pdf", "ChargingCount"+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "电池充放电统计数据");
    }    
    
   /**
    * 获取电池充放电统计数据
    * @param params
    * @return
    * @throws Exception
    * @author:zhangzq
    * @email:
    */
    private List<ChargingCountVo> getChargingCountData(CommonParamsVo params) throws Exception {
    	SysUserEntity user = this.getCurrentUser().getUser();
    	commonInitParamService.initParamsLimitCar(params, user, Arrays.asList("T_COMM_CAR_CHARGE_INFO","T_COMM_MFT_ALM"));
        List<ChargingCountVo> list = chargingCountService.getChargingCountData(params);
        return list;
    }
    
}
